/*
 * mma7455.h
 *
 * Created: 01.05.2012 12:43:10
 *  Author: Maxim Karban <maxim.karban@gmail.com>
 */ 

#include "stdint.h"
#include "i2c_master.h"

#ifndef MMA7455_H_
#define MMA7455_H_

#define MMA_DRPD  6
#define MMA_SPI3W 5
#define MMA_STON  4
#define MMA_GLVL1 3 
#define MMA_GLVL0 2
#define MMA_MODE1 1 
#define MMA_MODE0 0


#define MMA_MODE(a,b,c,d,e,f,g) \
  ( a << MMA_DRPD  | \
    b << MMA_SPI3W | \
    c << MMA_STON  | \
    d << MMA_GLVL1 | \
    e << MMA_GLVL0 | \
    f << MMA_MODE1 | \
    g << MMA_MODE0 )


extern uint8_t mmabuf[];
//#define MMA_MODE_I2C PORTC |= 1 << PC0
//#define MMA_MODE_SPI PORTC &= ~(1 << PC0)

#define MMAInit() i2c_write(0x3A, 0x16, MMA_MODE(0, 0, 0, 0, 0, 0, 1))

#define MMAGetAccel() i2c_read(mmabuf, 0x3A, 0x00, 6, 0, 1)

extern void MMADecode(int16_t * accel_x, int16_t * accel_y, int16_t * accel_z);
extern void MMAFilter(int16_t * accel_x, int16_t * accel_y, int16_t * accel_z);


#endif /* MMA7455_H_ */